﻿using MvvmCross.Platform;
using MvvmCross.Core.ViewModels;
using MvvmCross.Core.Views;
using System.Linq;

namespace Sidvall.UI.ViewModels
{
	public static class PresentationManager
	{
		#region GetPresentationBundle

		public static MvxBundle GetPresentationBundle(string childRegionName, bool addToHistory)
		{
			MvxBundle presentationBundle;

			presentationBundle = new MvxBundle();
			if (!string.IsNullOrWhiteSpace(childRegionName))
				presentationBundle.Data.Add(Sidvall.UI.Views.Region.RegionNameParameter, childRegionName);
			if (!addToHistory)
				presentationBundle.Data.Add(Sidvall.UI.Navigation.NavigationManager.AddToHistoryParameter, addToHistory.ToString());
			if (presentationBundle.Data.Count > 0)
				return presentationBundle;
			return null;
		}

		#endregion
		#region ShowViewModel

		public static void ShowViewModel(MvxViewModelRequest request)
		{
			IMvxViewDispatcher viewDispatcher;

			if (request == null)
				return;
			viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>();
			viewDispatcher.ShowViewModel(request);
		}

		#endregion
		#region ShowViewModels

		public static void ShowViewModels(System.Collections.Generic.IEnumerable<MvxViewModelRequest> requests)
		{
			IMvxViewDispatcher viewDispatcher;

			if (requests == null)
				return;
			if (!requests.Any())
				return;
			viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>();
			foreach (var request in requests)
				viewDispatcher.ShowViewModel(request);
		}

		#endregion
	}
}
